<?php
## include required files
/*******************************/ 
require_once '../includefiles.php';
require_once '../model/admindetails.php';
require_once '../model/config.php';
/*******************************/

## Create Objects
/*******************************/
$adminObj= new Model_AdminDetails();
$configObj = new Model_Config();
/*******************************/

##fetching the logo
$logoArr=$configObj->getConfigValueById(1);
$smarty->assign('logoArr', $logoArr);

if($_GET['id']!='')
{
	$admin_res=$adminObj->getUserValueByMdUserId($_GET['id']);
	$smarty->assign('admin_res', $admin_res);
}
if(isset($_POST['reset_btn'])){	
		## apply PHP validation for required fields whenever you submit the form in your project
		if(trim($_POST['pass']) != '') {					
				$adminArray=array();
				$adminArray['password']=md5($_POST['pass']);
				$adminObj->editUserValueById($adminArray,$_POST['id']);
				$_SESSION['msg'] = 'Your reset password successfully!';	
			} else { // password else
				$_SESSION['msg'] = 'Please enter your password';
		}
// main if closed	
}

## Assign success or error msg to smarty variable and unset session variable
if(trim($_SESSION['msg']) != '') {
	$smarty->assign('msg', $_SESSION['msg']);
	unset($_SESSION['msg']);
}

## Fetch footer logo and text setting
# Footer text
$footer_text = $configObj->getConfigValueById(2);
$smarty->assign('footer_text', $footer_text['config_value']);

# Footer logo
$footer_logo = $configObj->getConfigValueById(3);
$smarty->assign('footer_logo', $footer_logo['config_value']);

## Unset all the objects created which are on this page
unset($adminObj);
unset($configObj);

$smarty->display(TEMPLATEDIR_ADMIN. 'resetpassword.tpl');
unset($smarty);
?>